
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta charset="utf-8" />
    <title>UCTB.utils.st_map &#8212; UCTB  documentation</title>
    <link rel="stylesheet" href="../../../_static/nature.css" type="text/css" />
    <link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
    <script type="text/javascript" id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
    <script type="text/javascript" src="../../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../../_static/doctools.js"></script>
    <script type="text/javascript" src="../../../_static/language_data.js"></script>
    <link rel="index" title="Index" href="../../../genindex.html" />
    <link rel="search" title="Search" href="../../../search.html" /> 
  </head><body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../index.html">UCTB  documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../index.html" accesskey="U">Module code</a> &#187;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <h1>Source code for UCTB.utils.st_map</h1><div class="highlight"><pre>
<span></span>
<span class="c1"># Plot saptial-temporal map</span>
<div class="viewcode-block" id="st_map"><a class="viewcode-back" href="../../../UCTB.utils.html#UCTB.utils.st_map.st_map">[docs]</a><span class="k">def</span> <span class="nf">st_map</span><span class="p">(</span><span class="n">lat</span><span class="p">,</span> <span class="n">lng</span><span class="p">,</span> <span class="n">build_order</span><span class="p">,</span> <span class="n">meta_info</span><span class="p">,</span> <span class="n">file_name</span><span class="p">,</span>
           <span class="n">zoom</span><span class="o">=</span><span class="mi">11</span><span class="p">,</span> <span class="n">style</span><span class="o">=</span><span class="s1">&#39;light&#39;</span><span class="p">):</span>

    <span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
    <span class="kn">import</span> <span class="nn">plotly</span>
    <span class="kn">from</span> <span class="nn">plotly.graph_objs</span> <span class="k">import</span> <span class="n">Scattermapbox</span><span class="p">,</span> <span class="n">Layout</span>

    <span class="n">mapboxAccessToken</span> <span class="o">=</span> <span class="s2">&quot;pk.eyJ1Ijoicm1ldGZjIiwiYSI6ImNqN2JjN3l3NjBxc3MycXAzNnh6M2oxbGoifQ.WFNVzFwNJ9ILp0Jxa03mCQ&quot;</span>

    <span class="n">bikeStations</span> <span class="o">=</span> <span class="p">[</span><span class="n">Scattermapbox</span><span class="p">(</span>
        <span class="n">lon</span><span class="o">=</span><span class="n">lng</span><span class="p">,</span>
        <span class="n">lat</span><span class="o">=</span><span class="n">lat</span><span class="p">,</span>
        <span class="n">text</span><span class="o">=</span><span class="n">meta_info</span><span class="p">,</span>
        <span class="n">mode</span><span class="o">=</span><span class="s1">&#39;markers&#39;</span><span class="p">,</span>
        <span class="n">marker</span><span class="o">=</span><span class="nb">dict</span><span class="p">(</span>
            <span class="n">size</span><span class="o">=</span><span class="mi">6</span><span class="p">,</span>
            <span class="n">color</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;rgb(</span><span class="si">%s</span><span class="s1">, </span><span class="si">%s</span><span class="s1">, </span><span class="si">%s</span><span class="s1">)&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="mi">255</span><span class="p">,</span>
                                        <span class="mi">195</span> <span class="o">-</span> <span class="n">e</span> <span class="o">*</span> <span class="mi">195</span> <span class="o">/</span> <span class="nb">max</span><span class="p">(</span><span class="n">build_order</span><span class="p">),</span>
                                        <span class="mi">195</span> <span class="o">-</span> <span class="n">e</span> <span class="o">*</span> <span class="mi">195</span> <span class="o">/</span> <span class="nb">max</span><span class="p">(</span><span class="n">build_order</span><span class="p">))</span> <span class="k">for</span> <span class="n">e</span> <span class="ow">in</span> <span class="n">build_order</span><span class="p">],</span>
            <span class="n">opacity</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span>
        <span class="p">))]</span>
    
    <span class="n">layout</span> <span class="o">=</span> <span class="n">Layout</span><span class="p">(</span>
        <span class="n">title</span><span class="o">=</span><span class="s1">&#39;Bike Station Location &amp; The latest built stations with deeper color&#39;</span><span class="p">,</span>
        <span class="n">autosize</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
        <span class="n">hovermode</span><span class="o">=</span><span class="s1">&#39;closest&#39;</span><span class="p">,</span>
        <span class="n">showlegend</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
        <span class="n">mapbox</span><span class="o">=</span><span class="nb">dict</span><span class="p">(</span>
            <span class="n">accesstoken</span><span class="o">=</span><span class="n">mapboxAccessToken</span><span class="p">,</span>
            <span class="n">bearing</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span>
            <span class="n">center</span><span class="o">=</span><span class="nb">dict</span><span class="p">(</span>
                <span class="n">lat</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">median</span><span class="p">(</span><span class="n">lat</span><span class="p">),</span>
                <span class="n">lon</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">median</span><span class="p">(</span><span class="n">lng</span><span class="p">)</span>
            <span class="p">),</span>
            <span class="n">pitch</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span>
            <span class="n">zoom</span><span class="o">=</span><span class="n">zoom</span><span class="p">,</span>
            <span class="n">style</span><span class="o">=</span><span class="n">style</span>
        <span class="p">),</span>
    <span class="p">)</span>

    <span class="n">fig</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">(</span><span class="n">data</span><span class="o">=</span><span class="n">bikeStations</span><span class="p">,</span> <span class="n">layout</span><span class="o">=</span><span class="n">layout</span><span class="p">)</span>
    <span class="n">plotly</span><span class="o">.</span><span class="n">offline</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">fig</span><span class="p">,</span> <span class="n">filename</span><span class="o">=</span><span class="n">file_name</span><span class="p">)</span></div>
</pre></div>

          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
<div id="searchbox" style="display: none" role="search">
  <h3 id="searchlabel">Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="../../../search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" />
      <input type="submit" value="Go" />
    </form>
    </div>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../index.html">UCTB  documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../index.html" >Module code</a> &#187;</li> 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
        &#169; Copyright 2019, Di Chai, Leye Wang, Jin Xu, Wenjie Yang, Liyue Chen.
      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 2.2.1.
    </div>
  </body>
</html>